package com.golden.procedure.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.golden.procedure.domain.QueryRequest;
import com.golden.procedure.domain.SingleRequest;
import com.golden.procedure.domain.WorkCommentDO;
import com.golden.procedure.domain.WorkOrderBookDO;
import com.golden.procedure.domain.WorkOrderDO;
import com.golden.procedure.domain.WorkOrderExchangeDO;
import com.golden.procedure.domain.WorkSeatSchedulingDO;
import com.golden.procedure.domain.WorkSiteSeatDO;
import com.golden.procedure.domain.WorkerDO;
import com.golden.procedure.query.SchedulingQueryDO;
import com.golden.procedure.query.WorkOrderBookQueryDO;
import com.golden.procedure.result.MyPageResponse;
import com.golden.procedure.result.PageResponse;
import com.golden.procedure.result.ResultDO;
import com.golden.procedure.result.SingleResponse;
import com.golden.procedure.service.IWorkCommentService;
import com.golden.procedure.service.IWorkOrderBookService;
import com.golden.procedure.service.IWorkOrderService;
import com.golden.procedure.service.IWorkSiteSeatService;
import com.golden.procedure.service.IWorkerService;
import com.golden.procedure.util.EncryptedUtil;
import com.golden.procedure.util.HttpStatus;
import com.google.gson.Gson;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 摄控安排、预约等相关接口 <b>Description:</b><br>
 * 
 * @author Reading.Reagan</a>
 * @version 1.0
 * @Note <b>ProjectName:</b> procedure <br>
 *       <b>PackageName:</b> com.golden.procedure.controller <br>
 *       <b>ClassName:</b> WorkSchedulingController <br>
 *       <b>Date:</b> 2018年10月23日 上午10:20:54
 */
@RestController
@RequestMapping(value = "/api/scheduling")
public class WorkSchedulingController extends BaseController {

	@Autowired
	IWorkSiteSeatService workSiteSeatService;

	@Autowired
	IWorkOrderService workOrderService;

	@Autowired
	IWorkerService workerService;

	@Autowired
	IWorkOrderBookService workOrderBookService;

	@Autowired
	IWorkCommentService workCommentService;

	public static String encodeObject(SingleResponse<WorkSiteSeatDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeServiceQuery(PageResponse<WorkOrderBookQueryDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodePage(PageResponse<WorkSiteSeatDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeSeatPage(PageResponse<WorkSeatSchedulingDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeWorkOrderPage(PageResponse<WorkOrderDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodePhotographyPage(PageResponse<WorkOrderDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	public static String encodeCommentPage(PageResponse<WorkCommentDO> response, String encryptType) {
		Gson gson = new Gson();
		String jsonData = gson.toJson(response);
		try {
			return EncryptedUtil.encrypt(jsonData, encryptType);
		} catch (Exception e) {
			e.printStackTrace();
			return SYS_ERROR;
		}
	}

	@ApiOperation(value = "摄控安排列表", notes = "摄控安排列表")
	@ApiImplicitParams({ @ApiImplicitParam(name = "siteID", value = "上门组id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "schedulingDateStr", value = "摄控日期（时间戳）", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "queryKey", value = "查询字段Key（1-车号；2-服务人员；3-客户姓名/电话；4-预约人", required = false, dataType = "String"),
			@ApiImplicitParam(name = "queryValue", value = "查询字段值Value", required = false, dataType = "String") })
	@RequestMapping(value = "/query.json", method = RequestMethod.POST)
	public String query(@RequestBody QueryRequest<SchedulingQueryDO> request) {

		SchedulingQueryDO query = request.getData();
		if (query.getPageRows() > 0) {
			query.setPage(true);
		}

		MyPageResponse<WorkSiteSeatDO> response = new MyPageResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workSiteSeatService.queryByDay(query);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(0);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<WorkSiteSeatDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			List<Integer> numList = (List<Integer>) resultDO.getModel(ResultDO.THIRD_MODEL_KEY);
			if (null != numList && numList.size() > 1) {
				response.setSeatNum(numList.get(0));
				response.setSeatTotle(numList.get(1));
			}
			if (query.isPage()) {
				response.setTotal((Integer) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
			}
		} else {
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}
		return encodePage(response, PLANINTEXT);
	}

	@ApiOperation(value = "安排区域", notes = "安排区域")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "工位分组id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "province", value = "省", required = true, dataType = "String"),
			@ApiImplicitParam(name = "city", value = "市", required = true, dataType = "String"),
			@ApiImplicitParam(name = "district", value = "区县", required = true, dataType = "String") })
	@RequestMapping(value = "/setRegion.json", method = RequestMethod.POST)
	public String setRegion(@RequestBody SingleRequest<WorkSiteSeatDO> request) {
		// {"data":{"id":2353,"province":"500000","city":"500100","district":"500103"},
		// "version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkSiteSeatDO siteSeatsDO = request.getData();
		// TODO: 登录人员信息
		siteSeatsDO.setModifiID(9);
		siteSeatsDO.setModifi("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		// 根据工位组id设置服务区域
		ResultDO resultDO = workSiteSeatService.setRegion(siteSeatsDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SYSTEM_ERROR.getMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "安排车辆", notes = "安排车辆（每台车每日最多可安排两次）")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "工位分组id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "vechileCode", value = "车辆序号", required = true, dataType = "Integer") })
	@RequestMapping(value = "/setVechile.json", method = RequestMethod.POST)
	public String setVehicle(@RequestBody SingleRequest<WorkSiteSeatDO> request) {

		// {"data": {"id":2353,
		// "vechileIndex":1},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkSiteSeatDO siteSeatsDO = request.getData();

		// TODO: 登录人员信息
		siteSeatsDO.setModifiID(9);
		siteSeatsDO.setModifi("test");

		// 1. 根据工位组设置车辆
		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workSiteSeatService.setVechile(siteSeatsDO);
		if (!resultDO.isSuccess()) {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SYSTEM_ERROR.getMsg());
			return encodeObject(response, PLANINTEXT);
		}

		// 2. 设置车辆后，查找该工位组下已安排的工单
		// WorkOrderQueryDO queryDO = new WorkOrderQueryDO();
		// queryDO.setSiteSeatID(siteSeatsDO.getId());
		// resultDO = workerOrderService.query(queryDO);
		// if (resultDO.isSuccess()) {
		// List<WorkOrderDO> resList = (List<WorkOrderDO>)
		// resultDO.getModel(ResultDO.FIRST_MODEL_KEY);
		// for (WorkOrderDO data : resList) {
		// 根据查询出来的工单信息中的processInstanceID 进行流程更新
		// 完成车辆设置流程
		// List<Task> tasks = new ArrayList<Task>();
		// // TODO： 根据流程ID查询 人员未设置
		// List<Task> todoList =
		// taskService.createTaskQuery().processInstanceId(data.getProcessInstanceID())
		// .taskId(BonConstant.TASK_DEF_KEY_ORDER_SCHEDULE).taskAssignee(userName).active().list();
		// // 根据当前人未签收的任务
		// List<Task> unsignedTasks =
		// taskService.createTaskQuery().processInstanceId(processInstanceId)
		// .taskId(BonConstant.TASK_DEF_KEY_ORDER_SCHEDULE).taskCandidateUser(userName).active().list();
		// // 合并
		// tasks.addAll(todoList);
		// tasks.addAll(unsignedTasks);
		//
		// activitiClientAPI client = new activitiClientAPI();
		// // 根据流程的业务ID查询实体并关联
		// for (Task task : tasks) {
		// client.complete(task.getId(), null);
		//
		// // 添加任务记录
		// }
		// }
		// }
		response.setStatus(HttpStatus.SUCCESS.getErrorCode());
		response.setVersion(1);
		response.setMsg(HttpStatus.SUCCESS.getMsg());
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "安排等级", notes = "安排等级")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "工位分组id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "serviceClass", value = "服务等级（字典）", required = true, dataType = "Integer") })
	@RequestMapping(value = "/setServiceClass.json", method = RequestMethod.POST)
	public String setServiceClass(@RequestBody SingleRequest<WorkSiteSeatDO> request) {

		// {"data": {"id":2353,
		// "serviceClass":1},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkSiteSeatDO siteSeatsDO = request.getData();
		// TODO: 登录人员信息
		siteSeatsDO.setModifiID(9);
		siteSeatsDO.setModifi("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		// 根据工位组id设置服务区域
		ResultDO resultDO = workSiteSeatService.setServiceClass(siteSeatsDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SYSTEM_ERROR.getMsg());
		}
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "安排服务人员", notes = "根据服务角色添加员工")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "siteSeatID", value = "工位分组id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "employeeID", value = "员工ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "roleID", value = "角色ID", required = true, dataType = "Integer") })
	@RequestMapping(value = "/setWorker.json", method = RequestMethod.POST)
	public String setWorker(@RequestBody SingleRequest<WorkerDO> request) {
		// 1. 设置摄影师等人员
		// {"data": {"siteSeatID":2353,
		// "roleID":3,"employeeID":11},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkerDO workerDO = request.getData();
		workerDO.setAuthorID(9);
		workerDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		// 1. 根据工位组、角色设置人员
		ResultDO resultDO = workerService.setWorker(workerDO);
		if (!resultDO.isSuccess()) {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
			return encodeObject(response, PLANINTEXT);
		}

		// TODO： 根据工位组查询预约的工单，更新工单流程

		// 根据查询出来的工单信息中的processInstanceID 进行流程更新
		// 完成车辆设置流程
		// List<Task> tasks = new ArrayList<Task>();
		// // 根据当前人的ID查询
		// List<Task> todoList =
		// taskService.createTaskQuery().processInstanceId(processInstanceId).taskId("arrenageTeam")
		// .taskAssignee(userName).active().list();
		// // 根据当前人未签收的任务
		// List<Task> unsignedTasks =
		// taskService.createTaskQuery().processInstanceId(processInstanceId)
		// .taskId("arrenageTeam").taskCandidateUser(userName).active().list();
		// // 合并
		// tasks.addAll(todoList);
		// tasks.addAll(unsignedTasks);
		//
		// activitiClientAPI client = new activitiClientAPI();
		// // 根据流程的业务ID查询实体并关联
		// for (Task task : tasks) {
		// Map<String, Object> map = new HashMap<String, Object>();
		// map.put("inputUser", userName);
		// client.complete(task.getId(), map);
		// }
		response.setStatus(HttpStatus.SUCCESS.getErrorCode());
		response.setVersion(1);
		response.setMsg(HttpStatus.SUCCESS.getMsg());
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "更改服务人员", notes = "根据服务角色更改人员")
	@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "原服务人员id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "employeeID", value = "新员工ID", required = true, dataType = "Integer") })
	@RequestMapping(value = "/editWorker.json", method = RequestMethod.POST)
	public String editWorker(@RequestBody SingleRequest<WorkerDO> request) {
		// 1. 设置摄影师等人员
		WorkerDO workerDO = request.getData();
		workerDO.setAuthorID(9);
		workerDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		// 1. 根据工位组、角色设置人员
		ResultDO resultDO = workerService.editWorker(workerDO);
		if (!resultDO.isSuccess()) {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
			return encodeObject(response, PLANINTEXT);
		}

		// TODO： 根据工位组查询预约的工单，更新工单流程

		// 根据查询出来的工单信息中的processInstanceID 进行流程更新
		// 完成车辆设置流程
		// List<Task> tasks = new ArrayList<Task>();
		// // 根据当前人的ID查询
		// List<Task> todoList =
		// taskService.createTaskQuery().processInstanceId(processInstanceId).taskId("arrenageTeam")
		// .taskAssignee(userName).active().list();
		// // 根据当前人未签收的任务
		// List<Task> unsignedTasks =
		// taskService.createTaskQuery().processInstanceId(processInstanceId)
		// .taskId("arrenageTeam").taskCandidateUser(userName).active().list();
		// // 合并
		// tasks.addAll(todoList);
		// tasks.addAll(unsignedTasks);
		//
		// activitiClientAPI client = new activitiClientAPI();
		// // 根据流程的业务ID查询实体并关联
		// for (Task task : tasks) {
		// Map<String, Object> map = new HashMap<String, Object>();
		// map.put("inputUser", userName);
		// client.complete(task.getId(), map);
		// }
		response.setStatus(HttpStatus.SUCCESS.getErrorCode());
		response.setVersion(1);
		response.setMsg(HttpStatus.SUCCESS.getMsg());
		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "预约订单拍摄", notes = "预约订单（订单上摄控）")
	@ApiImplicitParams({ @ApiImplicitParam(name = "seatID", value = "席位id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workOrderID", value = "订单ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "smsFlag", value = "短信发送标识", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "remark", value = "备注", required = false, dataType = "String") })
	@RequestMapping(value = "/booking.json", method = RequestMethod.POST)
	public String booking(@RequestBody SingleRequest<WorkOrderBookDO> request) {

		// {"data":
		// {"seatID":10490,"workOrderID":3,"smsFlag":0,"remark":"预约拍摄"},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkOrderBookDO workOrderDO = request.getData();

		// TODO: 1. 预约订单/生成工单
		workOrderDO.setAuthorID(9);
		workOrderDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workOrderBookService.booking(workOrderDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "工单改期", notes = "工单改期")
	@ApiImplicitParams({ @ApiImplicitParam(name = "seatID", value = "席位id", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workOrderID", value = "工单ID", required = true, dataType = "Integer") })
	@RequestMapping(value = "/changeDate.json", method = RequestMethod.POST)
	public String changeDate(@RequestBody SingleRequest<WorkOrderBookDO> request) {
		// {"data":
		// {"id":9},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkOrderBookDO workOrderBookDO = request.getData();

		// TODO: 登录用户信息
		workOrderBookDO.setAuthorID(9);
		workOrderBookDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workOrderBookService.changeDate(workOrderBookDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "对调工单", notes = "对调工单")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "oldWorkOrderID", value = "工单ID1", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "workOrderID", value = "工单ID2", required = false, dataType = "Integer") })
	@RequestMapping(value = "/exchange.json", method = RequestMethod.POST)
	public String exchange(@RequestBody SingleRequest<WorkOrderExchangeDO> request) {
		// {"data":
		// {"id1":8,"id2":11},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkOrderExchangeDO exchangeDO = request.getData();

		// TODO: 登录用户信息
		exchangeDO.setAuthorID(9);
		exchangeDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workOrderBookService.exchangeDate(exchangeDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "取消预约", notes = "取消预约(该工单拍摄状态变为“未预约“，支持多个同时取消)")
	@ApiImplicitParam(name = "ids", value = "工单s", required = true, dataType = "Integer[]")
	@RequestMapping(value = "/cancel.json", method = RequestMethod.POST)
	public String cancel(@RequestBody SingleRequest<WorkOrderBookDO> request) {

		// {"data":
		// {"ids":[4,5]},"version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkOrderBookDO exchangeDO = request.getData();

		// TODO: 登录用户信息
		exchangeDO.setAuthorID(9);
		exchangeDO.setAuthor("test");

		SingleResponse<WorkSiteSeatDO> response = new SingleResponse<WorkSiteSeatDO>();
		ResultDO resultDO = workOrderBookService.cancel(exchangeDO);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
		} else {
			// 设置失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodeObject(response, PLANINTEXT);
	}

	@ApiOperation(value = "查询已预约的工单", notes = "查询已预约的工单")
	@ApiImplicitParams({ @ApiImplicitParam(name = "siteID", value = "上门组ID", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "province", value = "服务区域（省）", required = false, dataType = "String"),
			@ApiImplicitParam(name = "city", value = "服务区域（市）", required = false, dataType = "String"),
			@ApiImplicitParam(name = "dsitrict", value = "服务区域（省）", required = false, dataType = "String"),
			@ApiImplicitParam(name = "schedulingDateStr", value = "摄控日期", required = true, dataType = "String"),
			@ApiImplicitParam(name = "planStartOnStr", value = "时段(时间戳)", required = false, dataType = "String"),
			@ApiImplicitParam(name = "planEndOnStr", value = "时段(时间戳)", required = false, dataType = "String"),
			@ApiImplicitParam(name = "nameOrTel", value = "客户姓名或电话", required = false, dataType = "String") })
	@RequestMapping(value = "/queryBookOrder.json", method = RequestMethod.POST)
	public String queryBookOrder(@RequestBody QueryRequest<WorkOrderBookQueryDO> request) {

		// {"data":
		// {"siteID":1,"province":"500000","city":"500100","schedulingDateStr":"1535932800000","planStartOnStr":"1535947200000","planEndOnStr":"1535958000000"},
		// "version":1,"token":"W57m+iUG3/D+y/KY6V8ktuboDcz0nFIw62hRSUwHmUA="}
		WorkOrderBookQueryDO query = request.getData();
		if(query.getPageRows() > 0) {
			query.setPage(true);
		}

		PageResponse<WorkSeatSchedulingDO> response = new PageResponse<WorkSeatSchedulingDO>();
		ResultDO resultDO = workOrderBookService.queryBooked(query);
		if (resultDO.isSuccess()) {
			response.setStatus(HttpStatus.SUCCESS.getErrorCode());
			response.setVersion(1);
			response.setMsg(HttpStatus.SUCCESS.getMsg());
			response.setData((List<WorkSeatSchedulingDO>) resultDO.getModel(ResultDO.FIRST_MODEL_KEY));
			if(query.isPage()) {
				response.setTotal((int) resultDO.getModel(ResultDO.SECOND_MODEL_KEY));
			}
		} else {
			// 查询失败
			response.setStatus(HttpStatus.SYSTEM_ERROR.getErrorCode());
			response.setVersion(1);
			response.setMsg(resultDO.getErrorMsg());
		}

		return encodeSeatPage(response, PLANINTEXT);
	}

}
